# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from urllib.parse import urljoin
from datetime import datetime
import logging
import traceback
import re

_logger = logging.getLogger(__name__)


class OrderModel(models.Model):
    _name = 'order.model'
    _description = 'Order Model'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    _order = 'create_date desc'

    # BILL TO
    address = fields.Char(string='Address', )
    company = fields.Char(string='Company', )
    vat_number = fields.Char(string='Vat Number', )

    # ORDER DATA
    name = fields.Char(string='Workflow')
    purchase_order = fields.Char(string='Purchase Order')
    custom_code = fields.Char(string='Custom Code', )
    currency_code = fields.Char(string='Currency Code', )
    delivery_date = fields.Char(string='Delivery Date', )
    reference_number = fields.Char(string='Reference Number', )
    invoice_title = fields.Char(string='Invoice Title', )
    due_date = fields.Datetime(string='Due Date', )
    invoice_number = fields.Char(string='Invoice Number', )
    ocr_id = fields.Many2one('ocr.proxy')
    email_id = fields.Many2one('email.proxy')
    total_amount = fields.Float(string='Total Amount')
    ocr_score = fields.Float(string='OCR Score')
    invoice_date = fields.Datetime(string='Invoice Date', )
    state = fields.Selection([('draft', 'Draft'), ('review', 'Review'), ('create_po', 'Create Po'), ('gr', 'GR'), ('ir', 'IR'), ('paid', 'Paid')], default='draft')

    # PAYMENT DATA
    card_number = fields.Char(string='Card Number', )
    terms = fields.Text(string='Terms', )
    type = fields.Char(string='Type', )
    payment_date = fields.Datetime(string='Payment Date', )
    bank_name = fields.Char(string='Bank Name')
    bank_number = fields.Char(string='Bank Number')
    bank_swift = fields.Char(string='Bank Swift')

    #  Vendor Data
    vendor_name = fields.Char(string='Vendor Name')
    vendor_account_number = fields.Char(string='Account Number', )
    vendor_address = fields.Char(string='Vendor Address')
    vendor_email = fields.Char(string='Vendor Email')
    fax_number = fields.Char(string='Fax Number')
    web = fields.Char('Web')

    # Invoice Line
    invoice_line_ids = fields.One2many('invoice.line', 'order_id', string='Invoice Line')

    @api.model
    def create(self, vals):
        vals['name'] = self.env['ir.sequence'].sudo().next_by_code('order.model') or _('New')
        return super(OrderModel, self).create(vals)








